

** set path
// gl path ""

** open log
cap log close
log using "$path/table_a11.log", replace

** Trump recent foreclosures, with no county population weights

use "$path/foreclosures_analysis.dta", clear

gen trump = year == 2016
gen fore_trump = foreclosure_rate*trump
gen competitive = norm_vote > 0.4 & norm_vote < 0.6

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump, a(fips sy) cluster(fips)
local b1 = _b[foreclosure_rate_six]
local se1 = _se[foreclosure_rate_six]
local bint1 = _b[fore_trump]
local seint1 = _se[fore_trump]
local n1 = e(N)
local nclust1 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump, a(fips popyear) cluster(fips)
local b2 = _b[foreclosure_rate_six]
local se2 = _se[foreclosure_rate_six]
local bint2 = _b[fore_trump]
local seint2 = _se[fore_trump]
local n2 = e(N)
local nclust2 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump, a(i.fips##c.year sy) cluster(fips)
local b3 = _b[foreclosure_rate_six]
local se3 = _se[foreclosure_rate_six]
local bint3 = _b[fore_trump]
local seint3 = _se[fore_trump]
local n3 = e(N)
local nclust3 = e(N_clust)

bootstrap _b, rep(1e3) seed(94305) cluster(fips) force: reghdfe pres_vs foreclosure_rate_six fore_trump trump, a(i.fips##c.year popyear) cluster(fips)
local b4 = _b[foreclosure_rate_six]
local se4 = _se[foreclosure_rate_six]
local bint4 = _b[fore_trump]
local seint4 = _se[fore_trump]
local n4 = e(N)
local nclust4 = e(N_clust)

log close


quietly {
	cap log close
	set linesize 255
	log using "$path/foreclosure_trump_six_no_weights.tex", text replace
	
	noisily dis "\begin{table}[h]"
	noisily dis "\centering"
	noisily dis "\caption{\textbf{Effects of Recent Housing Foreclosures on Presidential Elections, County Level, 2004--2016: Testing for Trump-Clinton Effects.}"
	noisily dis "\label{tab:trump_six_no_weights}}"
	noisily dis "\begin{tabular}{lcccc}"
	noisily dis "\toprule \toprule"
	noisily dis " & \multicolumn{4}{c}{Dem Pres Vote Pct (0-100)}\\"
	noisily dis " & (1) & (2) & (3) & (4) \\"
	noisily dis "\midrule"
	noisily dis "Foreclosures Per 1,000 People & " %4.2f `b1' " & " %4.2f `b2' " & " %4.2f `b3' " & " %4.2f `b4'  "\\"
	noisily dis " & (" %4.2f `se1' ") & (" %4.2f `se2' ") & (" %4.2f `se3' ") & (" %4.2f `se4' ") \medskip \\"
	noisily dis "Foreclosures $ \times $ 2016 &  " %4.2f `bint1' " & " %4.2f `bint2' " & " %4.2f `bint3' " & " %4.2f `bint4'  "\\"
	noisily dis " & (" %4.2f `seint1' ") & (" %4.2f `seint2' ") & (" %4.2f `seint3' ") & (" %4.2f `seint4' ") \medskip \\"

	noisily dis " N & " %4.0fc `n1' " & " %4.0fc `n2' " & " %4.0fc `n3' " & " %4.0fc `n4' " \\ "
	noisily dis " \# Counties & "  %4.0fc `nclust1' " & " %4.0fc `nclust2' " & " %4.0fc `nclust3' " & " %4.0fc `nclust4' " \\ "
	noisily dis "County Fixed Effects & Y & Y & Y & Y  \\"
	noisily dis "State-Year Fixed Effects & Y & N & Y & N  \\"
	noisily dis "Pop Decile-Year Fixed Effects & N & Y & N & Y \\"
	noisily dis "County Linear Trends & N & N & Y & Y \\"
	noisily dis " Population Weights &  N & N & N & N \\"
	noisily dis "\bottomrule \bottomrule"
	noisily dis "\multicolumn{5}{p{.65\textwidth}}{\footnotesize Standard errors generated from 1,000 iterations of a county-level block bootstrap procedure.  "
	noisily dis "Main effect for 2016 is absorbed by fixed effects.}"
	noisily dis "\end{tabular}"
	noisily dis "\end{table}"
	
	log off
	
}
